package com.liao.product.controller;

import com.liao.common.entity.order.OrderItemEntity;
import com.liao.common.entity.product.SkuEntity;
import com.liao.common.utils.PageUtils;
import com.liao.product.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 商品SKU库存单元
 *
 * @author liao
 * @email 2858015963@qq.com
 * @date 2025-02-13 13:26:53
 */
@RestController
@RequestMapping("product/sku")
public class SkuController {
    @Autowired
    private SkuService skuService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public PageUtils<SkuEntity> list(@RequestParam Map<String, Object> params) {
        return skuService.queryPage(params);

    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public SkuEntity info(@PathVariable("skuId") String skuId) {
        SkuEntity byId = skuService.getById(skuId);
        return byId;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public void save(@RequestBody SkuEntity sku) {
        skuService.save(sku);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public void update(@RequestBody SkuEntity sku) {
        skuService.updateById(sku);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public void delete(@RequestBody String[] skuIds) {
        skuService.removeByIds(Arrays.asList(skuIds));

    }


    /**
     * 锁定库存
     */
    @RequestMapping("/lock")
    public void lock(@RequestBody List<OrderItemEntity> orderItemEntities) {
        skuService.lockStock(orderItemEntities);
    }

}
